package com.ruoyi.wechat.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.ImsYzzcSunGoods;
import com.ruoyi.merchant.domain.dto.ImsYzzcSunGoodsDto;
import com.ruoyi.merchant.domain.vo.ImsYzzcSunGoodsVo;
import com.ruoyi.merchant.service.IImsYzzcSunGoodsService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 车辆Controller
 *
 * @author ruoyi
 * @date 2024-08-28
 */
@RestController
@RequestMapping("/wechat/goods")
public class GoodsController extends BaseController
{
    @Autowired
    private IImsYzzcSunGoodsService imsYzzcSunGoodsService;
    private static final String FILE_DELIMETER = ",";

    /**
     * 查询车辆列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ImsYzzcSunGoods imsYzzcSunGoods)
    {
        startPage();
        List<ImsYzzcSunGoods> list = imsYzzcSunGoodsService.selectImsYzzcSunGoodsList(imsYzzcSunGoods);
        return getDataTable(list);
    }

    /**
     * 获取车辆详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imsYzzcSunGoodsService.selectGoodsById(id));
    }

    @GetMapping("filterImei")
    public AjaxResult filterImei(@RequestParam(required = false) String notImei,@RequestParam(required = false) String imei){

        return AjaxResult.success(imsYzzcSunGoodsService.filterImeiGoods(notImei, imei));
    }

    /**
     * 修改车辆
     */
    @PreAuthorize("@ss.hasPermi('merchant:goods:edit')")
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImsYzzcSunGoods imsYzzcSunGoods)
    {
        return toAjax(imsYzzcSunGoodsService.updateImsYzzcSunGoods(imsYzzcSunGoods));
    }


    @Anonymous
    @GetMapping("/selectCarsBySchedule")
    public TableDataInfo selectCarsBySchedule(ImsYzzcSunGoodsDto imsYzzcSunGoods)
    {
        if(ObjectUtils.isNotEmpty(imsYzzcSunGoods.getStructureStr())){
            String[] structStr=imsYzzcSunGoods.getStructureStr().split(",");
            List<Long> structureList=new ArrayList<Long>();
            for(int i=0;i<structStr.length;i++){
                structureList.add(Long.valueOf(structStr[i]));
            }
            imsYzzcSunGoods.setStructureList(structureList);
        }
        if(ObjectUtils.isNotEmpty(imsYzzcSunGoods.getEngageCarTypeStr())){
            String[] structStr=imsYzzcSunGoods.getEngageCarTypeStr().split(",");
            List<Long> structureList=new ArrayList<Long>();
            for(int i=0;i<structStr.length;i++){
                structureList.add(Long.valueOf(structStr[i]));
            }
            imsYzzcSunGoods.setEngageCarTypeList(structureList);
        }
        if(ObjectUtils.isNotEmpty(imsYzzcSunGoods.getGrarboxStr())){
            String[] grarboxStr=imsYzzcSunGoods.getGrarboxStr().split(",");
            List<Long> grarboxList=new ArrayList<Long>();
            for(int i=0;i<grarboxStr.length;i++){
                grarboxList.add(Long.valueOf(grarboxStr[i]));
            }
            imsYzzcSunGoods.setGrarboxList(grarboxList);
        }
        if(ObjectUtils.isNotEmpty(imsYzzcSunGoods.getCartypeStr())){
            String[] cartypeStr=imsYzzcSunGoods.getCartypeStr().split(",");
            List<Long> cartypeList=new ArrayList<Long>();
            for(int i=0;i<cartypeStr.length;i++){
                cartypeList.add(Long.valueOf(cartypeStr[i]));
            }
            imsYzzcSunGoods.setCartypeList(cartypeList);
        }
        if(ObjectUtils.isNotEmpty(imsYzzcSunGoods.getStatusStr())){
            String[] statusStr=imsYzzcSunGoods.getStatusStr().split(",");
            List<Long> statusList=new ArrayList<Long>();
            for(int i=0;i<statusStr.length;i++){
                statusList.add(Long.valueOf(statusStr[i]));
            }
            imsYzzcSunGoods.setStatusList(statusList);
        }
        startPage();
        List<ImsYzzcSunGoodsVo> list = imsYzzcSunGoodsService.selectCarsBySchedule(imsYzzcSunGoods);
        for(ImsYzzcSunGoodsVo goods:list){
//            String structureStr="";
//            if(goods.getStructure()==1){
//                structureStr="两厢";
//            }else{
//                structureStr="三厢";
//            }
//            String grarboxStr="";
//            if(goods.getGrarbox()==1){
//                grarboxStr="手动";
//            }else{
//                grarboxStr="自动";
//            }
//            String brandStr=getBrand(goods.getBrand());
            goods.setVehicleParams(new String[]{goods.getColour(), goods.getStructureStr(), goods.getGrarboxStr(), goods.getDisplacement(), goods.getBrandStr()});
            if(goods.getCartype()==1){
                goods.setCarTypePic("/prod-api/profile/vehicle/suv_20240416144040.jpg");
            }
            if(goods.getCartype()==2){
                goods.setCarTypePic("/prod-api/profile/vehicle/jc_20240416144128.jpg");
            }
            if(goods.getCartype()==3){
                goods.setCarTypePic("/prod-api/profile/vehicle/cdxny_20240416144029.png");
            }
            if(goods.getCartype()==4){
                goods.setCarTypePic("/prod-api/profile/vehicle/ydhd_20240416144047.jpg");
            }
            if(goods.getCartype()==5){
                goods.setCarTypePic("/prod-api/profile/vehicle/sw_20240416144117.jpg");
            }
            if(goods.getCartype()==6){
                goods.setCarTypePic("/prod-api/profile/vehicle/fc_20240416144139.jpg");
            }
            if(goods.getCartype()==7){
                goods.setCarTypePic("/prod-api/profile/vehicle/daba_20240416144143.jpg");
            }
            if(goods.getCartype()==8){
                goods.setCarTypePic("/prod-api/profile/vehicle/cp_20240416144133.jpg");
            }
        }
        return getDataTable(list);
    }

    public String getBrand(Long brand){

        String brandStr="";
        if (ObjectUtils.isNotEmpty(brand)) {
            if (brand == 1) {
                brandStr = "大众";
            }
            if (brand == 2) {
                brandStr = "奔驰";
            }
            if (brand == 3) {
                brandStr = "丰田";
            }
            if (brand == 4) {
                brandStr = "宝马";
            }
            if (brand == 5) {
                brandStr = "奥迪";
            }
            if (brand == 6) {
                brandStr = "比亚迪";
            }
            if (brand == 7) {
                brandStr = "本田";
            }
            if (brand == 8) {
                brandStr = "别克";
            }
            if (brand == 9) {
                brandStr = "福特";
            }
            if (brand == 10) {
                brandStr = "哈弗";
            }
            if (brand == 11) {
                brandStr = "埃尔法";
            }
            if (brand == 12) {
                brandStr = "腾势";
            }
            if (brand == 13) {
                brandStr = "劳斯莱斯";
            }
            if (brand == 14) {
                brandStr = "保时捷";
            }
            if (brand == 15) {
                brandStr = "路虎";
            }
            if (brand == 16) {
                brandStr = "东风";
            }
            if (brand == 17) {
                brandStr = "凯迪拉克";
            }
            if (brand == 18) {
                brandStr = "马自达";
            }
            if (brand == 19) {
                brandStr = "奇瑞";
            }
            if (brand == 20) {
                brandStr = "玛莎拉蒂";
            }
            if (brand == 21) {
                brandStr = "雪佛兰";
            }
            if (brand == 22) {
                brandStr = "宾利";
            }
            if (brand == 23) {
                brandStr = "起亚";
            }
            if (brand == 24) {
                brandStr = "雪铁龙";
            }
            if (brand == 25) {
                brandStr = "MINI";
            }
            if (brand == 26) {
                brandStr = "现代";
            }
        }
        return brandStr;

    }
}
